package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.blankj.utilcode.util.TimeUtils;
import com.blankj.utilcode.util.ToastUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.bean.RecordBean;
import flc.ast.databinding.ActivityPlayUriBinding;
import flc.ast.utils.AppSpUtils;

public class PlayUriActivity extends BaseAc<ActivityPlayUriBinding> {


    @Override
    protected int onCreate() {
        return R.layout.activity_play_uri;
    }

    @Override
    protected void initView() {
        mDataBinding.ivPlayUriBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.tvPlayUri.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvPlayUri:
                String videoPath = mDataBinding.etPlayUriText.getText().toString();
                if (TextUtils.isEmpty(videoPath)) {
                    ToastUtils.showShort(getString(R.string.please_input_play_uri));
                    return;
                }
                saveRecord(videoPath);
                PlayActivity.videoUri = videoPath;
                startActivity(PlayActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {

    }

    private void saveRecord(String videoPath) {
        List<RecordBean> listSave = new ArrayList<>();
        String time = TimeUtils.getNowString(new SimpleDateFormat("yyyy/MM/dd"));
        listSave.add(new RecordBean(getString(R.string.uri) + TimeUtils.getNowString(), "", "- -",
                time, videoPath));
        List<RecordBean> listSp = AppSpUtils.getPlayRecordList();
        if (listSp != null && listSp.size() > 0) {
            listSp.addAll(listSave);
            AppSpUtils.savePlayRecordList(listSp);
        } else {
            AppSpUtils.savePlayRecordList(listSave);
        }
    }

}